package com.ngc.mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ngc.mall.domain.ActivityDomain;
import com.ngc.mall.domain.CouponDomain;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityMapper extends BaseMapper<ActivityDomain> {
    @Insert({
            "<script>",
            "insert into activity_coupon(activity_id,coupon_id) values",
            "<foreach collection='couponIdList' item='item'  separator=',' >",
            "(#{activityId},#{item})",
            "</foreach>",
            "</script>"
    })
    Boolean relateCouponsById(@Param("activityId") Long activityId, @Param("couponIdList") List<Long> couponIdList);

    @Select({"select * from coupon where id in( select coupon_id from activity_coupon where activity_id = #{activityId})"})
    List<CouponDomain> findCouponByActivityId(@Param("activityId") Long activityId);

    @Delete({"delete from activity_coupon where activity_id=#{activityId} and coupon_id =#{couponId}"})
    Boolean unRelateCoupon(Long activityId,Long couponId);


}
